Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit94802e4

Browse files
committed
fix: fix some shortlist issues
1 parent89b399b commit94802e4

File tree

6 files changed

+30
-51
lines changed

6 files changed

+30
-51
lines changed

‎pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ classifiers = [
2323
]
2424
dependencies = [
2525
"lxml>=3.1.0",
26-
"typing_extensions",
26+
"typing_extensions>=4.9.0",
2727
]
2828
description ="Create, read, and update Microsoft Word .docx files."
2929
dynamic = ["version"]

‎src/docx/enum/base.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
importenum
66
importtextwrap
7-
fromtypingimportAny,Dict,Type,TypeVar
7+
fromtypingimportTYPE_CHECKING,Any,Dict,Type,TypeVar
88

9-
fromtyping_extensionsimportSelf
9+
ifTYPE_CHECKING:
10+
fromtyping_extensionsimportSelf
1011

1112
_T=TypeVar("_T",bound="BaseXmlEnum")
1213

@@ -69,7 +70,7 @@ def to_xml(cls: Type[_T], value: int | _T | None) -> str | None:
6970
"""XML value of this enum member, generally an XML attribute value."""
7071
# -- presence of multi-arg `__new__()` method fools type-checker, but getting a
7172
# -- member by its value using EnumCls(val) works as usual.
72-
returncls(value).xml_value# pyright: ignore[reportGeneralTypeIssues]
73+
returncls(value).xml_value
7374

7475

7576
classDocsPageFormatter:
@@ -129,9 +130,7 @@ def _member_defs(self):
129130
"""A single string containing the aggregated member definitions section of the
130131
documentation page."""
131132
members=self._clsdict["__members__"]
132-
member_defs= [
133-
self._member_def(member)formemberinmembersifmember.nameisnotNone
134-
]
133+
member_defs= [self._member_def(member)formemberinmembersifmember.nameisnotNone]
135134
return"\n".join(member_defs)
136135

137136
@property

‎src/docx/image/image.py

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
importos
1212
fromtypingimportIO,Tuple
1313

14-
fromtyping_extensionsimportSelf
15-
1614
fromdocx.image.exceptionsimportUnrecognizedImageError
1715
fromdocx.sharedimportEmu,Inches,Length,lazyproperty
1816

@@ -28,14 +26,14 @@ def __init__(self, blob: bytes, filename: str, image_header: BaseImageHeader):
2826
self._image_header=image_header
2927

3028
@classmethod
31-
deffrom_blob(cls,blob:bytes)->Self:
29+
deffrom_blob(cls,blob:bytes)->Image:
3230
"""Return a new |Image| subclass instance parsed from the image binary contained
3331
in `blob`."""
3432
stream=io.BytesIO(blob)
3533
returncls._from_stream(stream,blob)
3634

3735
@classmethod
38-
deffrom_file(cls,image_descriptor):
36+
deffrom_file(cls,image_descriptor:str|IO[bytes]):
3937
"""Return a new |Image| subclass instance loaded from the image file identified
4038
by `image_descriptor`, a path or file-like object."""
4139
ifisinstance(image_descriptor,str):
@@ -57,7 +55,7 @@ def blob(self):
5755
returnself._blob
5856

5957
@property
60-
defcontent_type(self):
58+
defcontent_type(self)->str:
6159
"""MIME content type for this image, e.g. ``'image/jpeg'`` for a JPEG image."""
6260
returnself._image_header.content_type
6361

@@ -167,12 +165,11 @@ def _from_stream(
167165
returncls(blob,filename,image_header)
168166

169167

170-
def_ImageHeaderFactory(stream):
171-
"""Return a |BaseImageHeader| subclass instance that knows how to parse the headers
172-
of the image in `stream`."""
168+
def_ImageHeaderFactory(stream:IO[bytes]):
169+
"""A |BaseImageHeader| subclass instance that can parse headers of image in `stream`."""
173170
fromdocx.imageimportSIGNATURES
174171

175-
defread_32(stream):
172+
defread_32(stream:IO[bytes]):
176173
stream.seek(0)
177174
returnstream.read(32)
178175

@@ -188,32 +185,27 @@ def read_32(stream):
188185
classBaseImageHeader:
189186
"""Base class for image header subclasses like |Jpeg| and |Tiff|."""
190187

191-
def__init__(self,px_width,px_height,horz_dpi,vert_dpi):
188+
def__init__(self,px_width:int,px_height:int,horz_dpi:int,vert_dpi:int):
192189
self._px_width=px_width
193190
self._px_height=px_height
194191
self._horz_dpi=horz_dpi
195192
self._vert_dpi=vert_dpi
196193

197194
@property
198-
defcontent_type(self):
195+
defcontent_type(self)->str:
199196
"""Abstract property definition, must be implemented by all subclasses."""
200-
msg= (
201-
"content_type property must be implemented by all subclasses of "
202-
"BaseImageHeader"
203-
)
197+
msg="content_type property must be implemented by all subclasses of ""BaseImageHeader"
204198
raiseNotImplementedError(msg)
205199

206200
@property
207-
defdefault_ext(self):
201+
defdefault_ext(self)->str:
208202
"""Default filename extension for images of this type.
209203
210204
An abstract property definition, must be implemented by all subclasses.
211205
"""
212-
msg= (
213-
"default_ext property must be implemented by all subclasses of "
214-
"BaseImageHeader"
206+
raiseNotImplementedError(
207+
"default_ext property must be implemented by all subclasses of ""BaseImageHeader"
215208
)
216-
raiseNotImplementedError(msg)
217209

218210
@property
219211
defpx_width(self):

‎src/docx/oxml/ns.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""Namespace-related objects."""
22

3-
fromtypingimportAny,Dict
3+
from__future__importannotations
44

5-
fromtyping_extensionsimportSelf
5+
fromtypingimportAny,Dict
66

77
nsmap= {
88
"a":"http://schemas.openxmlformats.org/drawingml/2006/main",
@@ -41,7 +41,7 @@ def clark_name(self) -> str:
4141
return"{%s}%s"% (self._ns_uri,self._local_part)
4242

4343
@classmethod
44-
deffrom_clark_name(cls,clark_name:str)->Self:
44+
deffrom_clark_name(cls,clark_name:str)->NamespacePrefixedTag:
4545
nsuri,local_name=clark_name[1:].split("}")
4646
nstag="%s:%s"% (pfxmap[nsuri],local_name)
4747
returncls(nstag)

‎src/docx/oxml/simpletypes.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,18 @@ def convert_from_xml(cls, str_value: str) -> Any:
3636
returnint(str_value)
3737

3838
@classmethod
39-
defconvert_to_xml(cls,value:Any)->str:
40-
...
39+
defconvert_to_xml(cls,value:Any)->str: ...
4140

4241
@classmethod
43-
defvalidate(cls,value:Any)->None:
44-
...
42+
defvalidate(cls,value:Any)->None: ...
4543

4644
@classmethod
4745
defvalidate_int(cls,value:object):
4846
ifnotisinstance(value,int):
4947
raiseTypeError("value must be <type 'int'>, got %s"%type(value))
5048

5149
@classmethod
52-
defvalidate_int_in_range(
53-
cls,value:int,min_inclusive:int,max_inclusive:int
54-
)->None:
50+
defvalidate_int_in_range(cls,value:int,min_inclusive:int,max_inclusive:int)->None:
5551
cls.validate_int(value)
5652
ifvalue<min_inclusiveorvalue>max_inclusive:
5753
raiseValueError(
@@ -129,8 +125,7 @@ def convert_to_xml(cls, value: bool) -> str:
129125
defvalidate(cls,value:Any)->None:
130126
ifvaluenotin (True,False):
131127
raiseTypeError(
132-
"only True or False (and possibly None) may be assigned, got"
133-
" '%s'"%value
128+
"only True or False (and possibly None) may be assigned, got"" '%s'"%value
134129
)
135130

136131

@@ -248,8 +243,7 @@ def validate(cls, value: Any) -> None:
248243
# must be an RGBColor object ---
249244
ifnotisinstance(value,RGBColor):
250245
raiseValueError(
251-
"rgb color value must be RGBColor object, got %s %s"
252-
% (type(value),value)
246+
"rgb color value must be RGBColor object, got %s %s"% (type(value),value)
253247
)
254248

255249

@@ -316,7 +310,7 @@ class ST_SignedTwipsMeasure(XsdInt):
316310
defconvert_from_xml(cls,str_value:str)->Length:
317311
if"i"instr_valueor"m"instr_valueor"p"instr_value:
318312
returnST_UniversalMeasure.convert_from_xml(str_value)
319-
returnTwips(int(str_value))
313+
returnTwips(int(round(float(str_value))))
320314

321315
@classmethod
322316
defconvert_to_xml(cls,value:int|Length)->str:

‎src/docx/text/paragraph.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
fromtypingimportTYPE_CHECKING,Iterator,List,cast
66

7-
fromtyping_extensionsimportSelf
8-
97
fromdocximporttypesast
108
fromdocx.enum.styleimportWD_STYLE_TYPE
119
fromdocx.oxml.text.runimportCT_R
@@ -29,9 +27,7 @@ def __init__(self, p: CT_P, parent: t.ProvidesStoryPart):
2927
super(Paragraph,self).__init__(parent)
3028
self._p=self._element=p
3129

32-
defadd_run(
33-
self,text:str|None=None,style:str|CharacterStyle|None=None
34-
)->Run:
30+
defadd_run(self,text:str|None=None,style:str|CharacterStyle|None=None)->Run:
3531
"""Append run containing `text` and having character-style `style`.
3632
3733
`text` can contain tab (``\\t``) characters, which are converted to the
@@ -82,7 +78,7 @@ def hyperlinks(self) -> List[Hyperlink]:
8278

8379
definsert_paragraph_before(
8480
self,text:str|None=None,style:str|ParagraphStyle|None=None
85-
)->Self:
81+
)->Paragraph:
8682
"""Return a newly created paragraph, inserted directly before this paragraph.
8783
8884
If `text` is supplied, the new paragraph contains that text in a single run. If
@@ -123,9 +119,7 @@ def rendered_page_breaks(self) -> List[RenderedPageBreak]:
123119
Most often an empty list, sometimes contains one page-break, but can contain
124120
more than one is rare or contrived cases.
125121
"""
126-
return [
127-
RenderedPageBreak(lrpb,self)forlrpbinself._p.lastRenderedPageBreaks
128-
]
122+
return [RenderedPageBreak(lrpb,self)forlrpbinself._p.lastRenderedPageBreaks]
129123

130124
@property
131125
defruns(self)->List[Run]:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp