Open dfarley1 opened 4 years ago
@dfarley1 what about other databases?
I haven't tried any other DBs, PostgreSQL is all I use and the netfields
package doesn't support any other DBs. However, the bitwise operators are universal to SQL so I would imagine you can "try" to do bitwise operations on any value that you can put in an SQL query.
I'm using the
netfields
(link) package and have a simple model:Given an entry like
prefix="00:50:C2:00:00:00", mask="ff:ff:ff:00:00:00"
I want to query with a MAC Addressmac="00:50:C2:12:34:56"
and find all prefixes which could contain the address. So I do a query likeMACAddressBlock.filter(prefix=F("mask").bitand(mac))
.This works in all my test cases, but Mypy complains that
Argument 1 to "bitand" of "Combinable" has incompatible type "str"; expected "int"
. Django-stubs claims onlyint
is supported (https://github.com/typeddjango/django-stubs/blob/90ed7f332def8922d4c72c046794a446b0e4cbc2/django-stubs/db/models/expressions.pyi#L38) but in PostgreSQL themacaddr
type supports bitwise operations with IP and MAC addresses expressed as strings.python
version: 3.6.5django
version: 2.2mypy
version: 0.760django-stubs
version: 1.4.0