Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
438d504e
Commit
438d504e
authored
Apr 05, 2014
by
Paul Sokolovsky
Browse files
objtype: Add equality test for type types.
parent
91cbe603
Changes
2
Hide whitespace changes
Inline
Side-by-side
py/objtype.c
View file @
438d504e
...
...
@@ -367,6 +367,16 @@ STATIC bool type_store_attr(mp_obj_t self_in, qstr attr, mp_obj_t value) {
return
false
;
}
STATIC
mp_obj_t
type_binary_op
(
int
op
,
mp_obj_t
lhs_in
,
mp_obj_t
rhs_in
)
{
switch
(
op
)
{
case
MP_BINARY_OP_EQUAL
:
// Types can be equal only if it's the same type structure,
// we don't even need to check for 2nd arg type.
return
MP_BOOL
(
lhs_in
==
rhs_in
);
}
return
NULL
;
}
const
mp_obj_type_t
mp_type_type
=
{
{
&
mp_type_type
},
.
name
=
MP_QSTR_type
,
...
...
@@ -375,6 +385,7 @@ const mp_obj_type_t mp_type_type = {
.
call
=
type_call
,
.
load_attr
=
type_load_attr
,
.
store_attr
=
type_store_attr
,
.
binary_op
=
type_binary_op
,
};
mp_obj_t
mp_obj_new_type
(
qstr
name
,
mp_obj_t
bases_tuple
,
mp_obj_t
locals_dict
)
{
...
...
tests/basics/types
_hash
.py
→
tests/basics/types
2
.py
View file @
438d504e
...
...
@@ -4,3 +4,9 @@ print(hash(int) != 0)
print
(
hash
(
list
)
!=
0
)
class
Foo
:
pass
print
(
hash
(
Foo
)
!=
0
)
print
(
int
==
int
)
print
(
int
!=
list
)
d
=
{}
d
[
int
]
=
float
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment