Skip to content

Using subclass of Range as default return type #559

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
kdorsel opened this issue Apr 21, 2020 · 1 comment · Fixed by #563
Closed

Using subclass of Range as default return type #559

kdorsel opened this issue Apr 21, 2020 · 1 comment · Fixed by #563

Comments

@kdorsel
Copy link
Contributor

kdorsel commented Apr 21, 2020

  • asyncpg version: 0.20.1
  • PostgreSQL version: 12.1
  • Python version: 3.7.7
  • Platform: macOS 10.15.4
  • Do you use pgbouncer?: No
  • Did you install asyncpg with pip?: Yes

I created a subclass of the Range type as follows:

from asyncpg.types import Range as Rg

class Range(Rg):
    def issubset(self, other):
        return self._lower >= other._lower and self._upper <= other._upper

    def issuperset(self, other):
        return self._upper >= other._upper and self._lower <= other._lower

    def size(self):
        return self._upper - self._lower

Would it be possible to have this subclass used automatically instead of the default type?

Both set_type_codec and set_builtin_type_codec don't seem to be able to do it.

@elprans
Copy link
Member

elprans commented Apr 23, 2020

These methods seem useful enough to be included in the default implementation. Feel free to submit a PR to include them.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants