-
Notifications
You must be signed in to change notification settings - Fork 83
mypy: Fix all union-attr #366
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
base: main
Are you sure you want to change the base?
Conversation
distutils/command/build_py.py
Outdated
|
|
||
| def build_packages(self) -> None: | ||
| for package in self.packages: | ||
| for package in self.packages or (): |
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.
This is a change in behaviour as it would graciously do nothing instead of raising if self.packages is still None.
If it makes more sense to raise, a clearer error than TypeError: 'NoneType' object is not iterable can be raised instead.
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.
Presumably self.packages is expected not to be None at this point. I'd rather see it enforced that it's not None by the time it reaches this point. That's probably more work than it's worth, so for a local fix, let's just do an explicit check (if self.packages is None raise a clear error).
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.
Feel free to update the new message to your likings !
| _wordchars_re = re.compile(rf'[^\\\'\"{string.whitespace} ]*') | ||
| _squote_re = re.compile(r"'(?:[^'\\]|\\.)*'") | ||
| _dquote_re = re.compile(r'"(?:[^"\\]|\\.)*"') |
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.
This isn't exactly "heavy computing" is it? Did it need to be done lazily ?
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.
Agreed. Looks like premature optimization. Even the re.compile calls are probably premature. Probably could have just used simple strings and compiled on demand and relied on caching in the re module to avoid duplicate work, but this approach is clean and simple enough.
| _wordchars_re = re.compile(rf'[^\\\'\"{string.whitespace} ]*') | ||
| _squote_re = re.compile(r"'(?:[^'\\]|\\.)*'") | ||
| _dquote_re = re.compile(r'"(?:[^"\\]|\\.)*"') |
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.
Agreed. Looks like premature optimization. Even the re.compile calls are probably premature. Probably could have just used simple strings and compiled on demand and relied on caching in the re module to avoid duplicate work, but this approach is clean and simple enough.
distutils/command/build_py.py
Outdated
|
|
||
| def build_packages(self) -> None: | ||
| for package in self.packages: | ||
| for package in self.packages or (): |
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.
Presumably self.packages is expected not to be None at this point. I'd rather see it enforced that it's not None by the time it reaches this point. That's probably more work than it's worth, so for a local fix, let's just do an explicit check (if self.packages is None raise a clear error).
| assert isinstance(cc, str) | ||
| assert isinstance(cxx, str) | ||
| assert isinstance(cflags, str) | ||
| assert isinstance(ccshared, str) | ||
| assert isinstance(ldshared, str) | ||
| assert isinstance(ldcxxshared, str) | ||
| assert isinstance(shlib_suffix, str) | ||
| assert isinstance(ar_flags, str) | ||
| ar = os.environ.get('AR', ar) | ||
| assert isinstance(ar, str) |
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.
I mentioned in another PR - I'm not sure these changes are stable. I'm worried there are edge cases that would begin to fail with this change. Let's be confident that this change doesn't break anything (and consider using casts to retain the current behavior if appropriate).
1d367ee to
9876b34
Compare
No description provided.