-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix most mypy attr-defined
& pyright reportAttributeAccessIssue
by explicitly defining attributes on classes
#4535
Conversation
@@ -153,6 +153,7 @@ def run(self): | |||
self._create_wheel_file(bdist_wheel) | |||
except Exception: | |||
traceback.print_exc() | |||
# TODO: Fix false-positive [attr-defined] in typeshed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2203891
to
b8594db
Compare
setuptools/extension.py
Outdated
_full_name = "" #: Private API, internal use only. | ||
_links_to_dynamic = False #: Private API, internal use only. | ||
_needs_stub = False #: Private API, internal use only. | ||
_file_name = "" #: Private API, internal use only. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is one very edge-y case where it is useful to not define default values beforehand: to avoid people forgetting to call finalize_options
if they modify the extension list like in #4529.
Tricky... In this case I feel like would like to have the cake (static type annotations) but eat it too (have the exception happening if someone forgets to call finalize_options
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe wrap in a if TYPE_CHECKING
and just use the type annotations instead of assigning a value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One could also declare the attribute type without a default value:
>>> class A:
... foo: str
... bar: str
...
>>> A().foo
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'A' object has no attribute 'foo'
If it's an issue with static checkers, then it can be guarded by if TYPE_CHECKING
. Either way I'll add a comment that a potential AttributeError
is expected and wanted. You can have your cake and eat it too, here 😄
1008fc0
to
a0cf7e1
Compare
New missing coverage https://github.com/pypa/setuptools/actions/runs/10306778328/job/28530606282?pr=4535#step:5:108
Is better resolved by jaraco/skeleton#130 |
Thank you! |
Summary of changes
Fix most mypy
attr-defined
& pyrightreportAttributeAccessIssue
for #2345 by explicitly defining attributes on classesI have some ideas on how to address the last
attr-defined
cause byDistributionMetadatalicense_files
DistributionMetadata.license_file
, but that's out of scope for this PR.get_finalized_command
,reinitialize_command
,get_command_obj
andget_command_class
still require casting, but that should be fixed in typeshed.Pull Request Checklist
newsfragments/
.(See documentation for details)