Refactor duplicated codes in exception creations#3402
Conversation
5abd75d to
04de53d
Compare
_ssl exception creations04de53d to
5c9c937
Compare
|
Uhm... I have no idea why rusttests have failed 😂 |
|
@Snowapril Look upside to find frozen lib errors |
5c9c937 to
2ca6a94
Compare
| // collect to context | ||
| for item in items.iter_mut() { | ||
| let r = item.try_split_attr_mut(|attrs, item| { | ||
| // If attribute is #[pyattr] and item is ItemFn, then |
There was a problem hiding this comment.
this is causing issues someplace but I can't track it down. Removing it from here and moving the static_cell to new_exception_type should be a viable alternative though.
There was a problem hiding this comment.
Moving static_cell to new_exception_type may solve that test failures. But we need to declare it as macro as each functions need its own static_cell. Approach with procedural-macro is best I think as it also solve other stuffs (#[pyattr] attached function in module which is not exception-type)
After more trying, I would mention you. sorry 😢
There was a problem hiding this comment.
Ah, right. Adding an error/exception argument to pyattr then? Have it only applied on attributes that are meant to denote errors.
There was a problem hiding this comment.
Oh . I missed your comment. I add "once" keyword to #[pyattr] like #[pyattr(name = "blahblah", once)] for that exceptions.
There was a problem hiding this comment.
I am not sure this is fit for here, but adding a field to ALLOWED_NAMES allows to read it from ItemMeta.
(with a new AttrItemMeta)
If you are interested in, check how ClassItemMeta handles metaclass. If this is not fit for here, still AttrItemMeta is preferred not to allow other simple items to have once.
There was a problem hiding this comment.
Sorry for late 😂 I moved static_cell wrapping code to get_module_item of AttributeItem.
Use AttrItemMeta::from_attr for ItemFn and replace original once keyword checking code to attr_meta.inner()._bool("once")? . For the other cases, Item::Const and Item::Use, just use SimpleItemMeta::from_attr as they do not have once keyword ever. Please take a look this commit 7f2fd97.
Thanks 😊
7f2fd97 to
d2fe92f
Compare
When we have to add #[pyattr] with function, that function must be called only once when module is imported. In previous, we did it with add static_cell for each function or skip it(undesired). I thought these static_cell stmt for all of each function in modules are quite duplicated. Thus, I add wrapping code when the given item is `ItemFn` and have `#[pyattr]`. Signed-off-by: snowapril <sinjihng@gmail.com>
Signed-off-by: snowapril <sinjihng@gmail.com>
Signed-off-by: snowapril <sinjihng@gmail.com>
At previous, `vm.ctx.new_class` did role for adding exception in module-level. This commit add `new_exception_type` for doing that part of role. As cpython implementation, if no bases is given, pass `exception_type` by default Signed-off-by: snowapril <sinjihng@gmail.com>
Replace `new_class` method call for module-level exceptions to newly added `new_exception_type` Signed-off-by: snowapril <sinjihng@gmail.com>
Signed-off-by: snowapril <sinjihng@gmail.com>
d2fe92f to
97f3434
Compare
This revision implements below
#[pyattr(once)]attached functions with static_cell! codes#[pyattr]attached.new_exception_typemethod for creating module-level exceptions.