Fix overlapping slots, base classes without slots by ariebovenberg · Pull Request #7589 · sqlalchemy/sqlalchemy · GitHub
Skip to content

Fix overlapping slots, base classes without slots - #7589

Closed
ariebovenberg wants to merge 8 commits into
sqlalchemy:mainfrom
ariebovenberg:fix-slots
Closed

ariebovenberg wants to merge 8 commits into
sqlalchemy:mainfrom
ariebovenberg:fix-slots

Conversation

@ariebovenberg

@ariebovenberg ariebovenberg commented Jan 19, 2022

Copy link
Copy Markdown
Contributor

Some __slots__ were not in order.

Fixes #7527

Description

I'm fixing two types of slots mistakes:

  • remove overlapping slots (i.e. slots already defined on a base class)
  • fix broken inheritance (i.e. slots class inheriting from a non-slots class)
    • slots added to base class TransactionalContext. It seemed to use two attributes, which I've added as slots.
    • empty slots removed from ORMOption. Its base class explicitly makes use of __dict__ so empty slots don't add anything.
    • empty slots added to PostLoader. It doesn't appear to use any slots not already defined on its base classes.
    • empty slots added to IterateMappersMixin. It doesn't appear to use any slots not already defined on its subclasses.
    • empty slots added to ImmutableContainer. It doesn't use any fields.
    • empty slots added to OperatorType. It's a protocol.
    • empty slots added to InternalTraversal, _HasTraversalDispatch. They don't seem to use attributes on their own.

Checklist

This pull request is:

  • A short code fix
    • please include the issue number, and create an issue if none exists, which
      must include a complete example of the issue. one line code fixes without an
      issue and demonstration will not be accepted.
    • Please include: Fixes: #<issue number> in the commit message
    • please include tests. one line code fixes without tests will not be accepted.

Have a nice day!

@ariebovenberg ariebovenberg changed the title remove overlapping slots already defined in base classes Fix overlapping slots, base classes without slots Jan 20, 2022
@zzzeek

zzzeek commented Jan 20, 2022

Copy link
Copy Markdown
Member

@ariebovenberg

Copy link
Copy Markdown
Contributor Author

@zzzeek yes! I'd like to keep it in draft until all slots have been fixed, but I do need full CI runs to ensure nothing gets messed up 🙏

@zzzeek
zzzeek requested a review from sqla-tester January 20, 2022 18:55

@sqla-tester sqla-tester left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, this is sqla-tester setting up my work on behalf of zzzeek to try to get revision c5aacf4 of this pull request into gerrit so we can run tests and reviews and stuff

@zzzeek

zzzeek commented Jan 20, 2022

Copy link
Copy Markdown
Member

OK the github actions will run each time now. the gerrit review is a separate CI that I always invoke manually but the GH actions are enough for you to develop.

@zzzeek

zzzeek commented Jan 20, 2022

Copy link
Copy Markdown
Member

note I have some slots related changes coming through soon so that we can use slots more easily: https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3532

@sqla-tester

Copy link
Copy Markdown
Collaborator

New Gerrit review created for change c5aacf4: https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3548

@CaselIT

CaselIT commented Jan 20, 2022

Copy link
Copy Markdown
Member

OK the github actions will run each time now. the gerrit review is a separate CI that I always invoke manually but the GH actions are enough for you to develop.

nope, only once we merge this. since it's a new contributor we have to approve each time.

@ariebovenberg ping us when you want the test to run

@ariebovenberg

Copy link
Copy Markdown
Contributor Author

@CaselIT thanks for your patience -- I need some time to get familiar with the CI setup.

Am I correct in considering these failures/aborts unrelated?

@CaselIT

CaselIT commented Jan 20, 2022

Copy link
Copy Markdown
Member

The github ones are fine, so it's probably something unrelated.

Once you want to re-run the complete suite we can make to bot update the existing gerrit

@zzzeek

zzzeek commented Jan 20, 2022

Copy link
Copy Markdown
Member

I tried adding Python 3.11.0a4 to gerrit / jenkins today and it was a total failure. ignore anything on gerrit for now.

@sqla-tester

Copy link
Copy Markdown
Collaborator

mike bayer (zzzeek) wrote:

recheck

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3548

@ariebovenberg

Copy link
Copy Markdown
Contributor Author

Alright, the slots fixes seem complete from my end. I've edited the top comment with a list of fixed slots and reasoning behind each of them.

Questions for you:

  1. You mention "Please include: Fixes: #<issue number> in the commit message". Should I squash the comments into one commit with this addition? Or add them to each commit?
  2. Regarding tests: I would (of course 😄 ) suggest slotscheck, which I developed. I've recently added slotscheck to instagram/LibCST and dry-python/returns if you're curious what this looks like.

@CaselIT

CaselIT commented Jan 21, 2022

Copy link
Copy Markdown
Member

regarding 1, no, it's fine as multiple commits since it will be squashed when importing it in gerrit (the change will be merged by gerrit, not from github)

@CaselIT

CaselIT commented Jan 21, 2022

Copy link
Copy Markdown
Member

can we make this ready for review?

@ariebovenberg
ariebovenberg marked this pull request as ready for review January 21, 2022 17:45
@CaselIT
CaselIT requested a review from sqla-tester January 21, 2022 17:54

@sqla-tester sqla-tester left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, this is sqla-tester setting up my work on behalf of CaselIT to try to get revision 4f3f665 of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester

Copy link
Copy Markdown
Collaborator

Patchset 4f3f665 added to existing Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3548

@sqla-tester

Copy link
Copy Markdown
Collaborator

mike bayer (zzzeek) wrote:

recheck

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3548

@sqla-tester

Copy link
Copy Markdown
Collaborator

mike bayer (zzzeek) wrote:

we were having some CI issues a week ago which are fixed, not sure of the status of this so let's see if it passes CI

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3548

@ariebovenberg

Copy link
Copy Markdown
Contributor Author

Looks like some fresh issues that are likely caused by the slots change, likecannot create weak reference to 'RootTransaction' object. Will attempt a fix

@ariebovenberg

Copy link
Copy Markdown
Contributor Author

@CaselIT could you kick off a CI run -- the weakref issue should be fixed. There may be more...

@CaselIT
CaselIT requested a review from sqla-tester January 31, 2022 23:40

@sqla-tester sqla-tester left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, this is sqla-tester setting up my work on behalf of CaselIT to try to get revision b6f4e8b of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester

Copy link
Copy Markdown
Collaborator

Patchset b6f4e8b added to existing Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3548

@ariebovenberg

ariebovenberg commented Feb 1, 2022

Copy link
Copy Markdown
Contributor Author

I've rebased from main, which resulted in a few more slots issues.

@zzzeek I think I'm missing some of the background on orm.interfaces:ORMOption and sql.base:Options. These classes seem to explicitly use __dict__ in their methods, while __dict__ doesn't get created if slots are defined in the full MRO. It seems to me __slots__ = () can be removed from these classes.

Could you kick off another CI run?

@CaselIT
CaselIT requested a review from sqla-tester February 1, 2022 20:08

@sqla-tester sqla-tester left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, this is sqla-tester setting up my work on behalf of CaselIT to try to get revision 70a9c4d of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester

Copy link
Copy Markdown
Collaborator

Patchset 70a9c4d added to existing Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3548

@sqla-tester

Copy link
Copy Markdown
Collaborator

mike bayer (zzzeek) wrote:

this looks great! did you say that you have a tool that lints for these? if it's mature enough we can have it as part of our .pre-commit config, if it can just alert us to new slots changes that are overlapping or missing.

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3548

@sqla-tester

Copy link
Copy Markdown
Collaborator

Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3548 has been merged. Congratulations! :)

@ariebovenberg
ariebovenberg deleted the fix-slots branch February 4, 2022 19:13
@ariebovenberg

Copy link
Copy Markdown
Contributor Author

@ariebovenberg ariebovenberg mentioned this pull request Feb 5, 2022
1 task
sqlalchemy-bot pushed a commit that referenced this pull request Feb 7, 2022
As discussed in #7589, `slotscheck` can prevent slots-related mistakes from creeping back in.

Plan for now is to have slotscheck part of the "lint" tests
(renamed from pep8) that will run for CI and github actions.

To support slotscheck's runtime nature, slotscheck is
run twice, first with cython exts enabled and then
with them disabled via new environment variable.
Also added sqlalchemy[mypy] dependency to support slots
checking the mypy plugin.

Found and fixed one more `__slots__` issue by disabling C
exts.

Closes: #7670
Pull-request: #7670
Pull-request-sha: 3e77fe5

Change-Id: I90cdd284cdcee316a38856ba94d72ffc98947c5a
relsunkaev pushed a commit to relsunkaev/sqlalchemy that referenced this pull request Feb 15, 2022
Some `__slots__` were not in order.

Fixes sqlalchemy#7527

### Description

I'm fixing two types of slots mistakes:
- [x] remove overlapping slots (i.e. slots already defined on a base class)
- [x] fix broken inheritance (i.e. slots class inheriting from a non-slots class)
  - [x] slots added to base class `TransactionalContext`. It seemed to use two attributes, which I've added as slots.
  - [x] empty slots removed from `ORMOption`. Its base class explicitly makes use of `__dict__` so empty slots don't add anything.
  - [x] empty slots added to `PostLoader`. It doesn't appear to use any slots not already defined on its base classes.
  - [x] empty slots added to `IterateMappersMixin`. It doesn't appear to use any slots not already defined on its subclasses.
  - [x] empty slots added to `ImmutableContainer`. It doesn't use any fields.
  - [x] empty slots added to `OperatorType`. It's a protocol.
  - [x] empty slots added to `InternalTraversal`, `_HasTraversalDispatch`. They don't seem to use attributes on their own.

### Checklist

This pull request is:

- [x] A short code fix
	- please include the issue number, and create an issue if none exists, which
	  must include a complete example of the issue.  one line code fixes without an
	  issue and demonstration will not be accepted.
	- Please include: `Fixes: #<issue number>` in the commit message
	- please include tests.   one line code fixes without tests will not be accepted.

**Have a nice day!**

Closes: sqlalchemy#7589
Pull-request: sqlalchemy#7589
Pull-request-sha: 70a9c4d

Change-Id: I6c6e3e69c3c34d0f3bdda7f0684849834fdd1863
relsunkaev pushed a commit to relsunkaev/sqlalchemy that referenced this pull request Feb 15, 2022
As discussed in sqlalchemy#7589, `slotscheck` can prevent slots-related mistakes from creeping back in.

Plan for now is to have slotscheck part of the "lint" tests
(renamed from pep8) that will run for CI and github actions.

To support slotscheck's runtime nature, slotscheck is
run twice, first with cython exts enabled and then
with them disabled via new environment variable.
Also added sqlalchemy[mypy] dependency to support slots
checking the mypy plugin.

Found and fixed one more `__slots__` issue by disabling C
exts.

Closes: sqlalchemy#7670
Pull-request: sqlalchemy#7670
Pull-request-sha: 3e77fe5

Change-Id: I90cdd284cdcee316a38856ba94d72ffc98947c5a
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.

Several classes have __slots__, but not their bases do not

4 participants