Since the OP mentions in a comment:
I want 1 and 2
to return an instance
of my class.
I think it's important to point out that this is entirely impossible: Python does not let you alter built-in types (and, in particular, their special methods). Literal 1
will always be an instance of built-in type int
, and in any case the basic semantics of the and
operator are not overridable anyway -- a and b
is always identical to b if a else a
for any a
and b
(no bool
coercion involved, even though the OP appears to mistakenly believe one is happening).
Restating this crucial point: the value of a and b
is always, unchangeably either a
or b
-- there is no way to break this semantic constraint (even if a
and b
were instances of your own peculiar classes -- even less so of course when they're constrained to be instances of Python's built-in int
!-).