Skip to content

Conversation

@Avasam
Copy link
Contributor

@Avasam Avasam commented May 4, 2025

No description provided.


def build_packages(self) -> None:
for package in self.packages:
for package in self.packages or ():
Copy link
Contributor Author

@Avasam Avasam May 4, 2025

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.

Copy link
Member

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).

Copy link
Contributor Author

@Avasam Avasam Oct 17, 2025

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 !

@Avasam Avasam changed the title Re-organize mypy errors mypy: Fix all union-attr May 4, 2025
Comment on lines +235 to +237
_wordchars_re = re.compile(rf'[^\\\'\"{string.whitespace} ]*')
_squote_re = re.compile(r"'(?:[^'\\]|\\.)*'")
_dquote_re = re.compile(r'"(?:[^"\\]|\\.)*"')
Copy link
Contributor Author

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 ?

Copy link
Member

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.

Comment on lines +235 to +237
_wordchars_re = re.compile(rf'[^\\\'\"{string.whitespace} ]*')
_squote_re = re.compile(r"'(?:[^'\\]|\\.)*'")
_dquote_re = re.compile(r'"(?:[^"\\]|\\.)*"')
Copy link
Member

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.


def build_packages(self) -> None:
for package in self.packages:
for package in self.packages or ():
Copy link
Member

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).

Comment on lines +327 to +336
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)
Copy link
Member

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).

@Avasam Avasam force-pushed the mypy--Fix-all-union-attr branch from 1d367ee to 9876b34 Compare October 17, 2025 15:49
This was referenced Oct 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants