在尝试将字符串转换为我编写的扩展类时,我看到了一些奇怪的行为int.这是一个简单的程序,演示了我的问题:
class MyInt(int):
pass
toInt = '123456789123456789123456789'
print "\nConverting to int..."
print type(int(toInt))
print "\nConverting to MyInt..."
print type(MyInt(toInt))
Run Code Online (Sandbox Code Playgroud)
既然MyInt是空的,我预计它的行为就像一个int.相反,这是我从上面的程序得到的输出:
Converting to int...
<type 'long'>
Converting to MyInt...
Traceback (most recent call last):
File "int.py", line 9, in <module>
print type(MyInt(toInt))
OverflowError: long int too large to convert to int
Run Code Online (Sandbox Code Playgroud)
字符串无法转换为MyInt!我写的方式如何MyInt导致它的行为与基类不同?在这种情况下,似乎有某种最大值MyInt; 当在Python中扩展内置类时,还有其他属性会被隐式强加吗?最后,有没有办法改变,MyInt以便它不再具有这个最大值?
I'm using apollo-server and testing using GraphiQL in my browser. I set up my resolvers based on Apollo's GitHunt-API example, but the resolver on the field "review.extraStuff" never gets called.
const rootResolvers = {
review(root, args, context) {
console.log('resolving review');
return {'HasErrors': true}
}
}
const extraStuff = (root, args, context) => {
console.log('resolving extraStuff');
return "yes";
}
rootResolvers.review.extraStuff = extraStuff;
export default {
RootQuery: rootResolvers
};
Run Code Online (Sandbox Code Playgroud)
const Review = `
type Review {
HasErrors: Boolean
extraStuff: …Run Code Online (Sandbox Code Playgroud)